package com.mxw.account.mapper;

import com.mxw.account.enums.InvoiceStatusEnum;
import com.mxw.account.mapper.domain.AccountEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Description TODO
 * @Author RingKo
 * @Date 2021/12/16 20:35
 * @Version 1.0
 */
@Repository
public interface AccountRepository extends JpaRepository<AccountEntity, Integer> {
  Page<AccountEntity> findByAccountCodeAndAccountName(String accountCode, String accountName, Pageable pageable);

  List<AccountEntity> findByAccountName(String accountName);

  List<AccountEntity> findByStatusIn(List<InvoiceStatusEnum> status);

  AccountEntity findFirstByStatusInOrderByIdDesc(List<InvoiceStatusEnum> status);

  @Query(
      value =
          "select *,FIELD(status, '4','1','5','7') from account",
      nativeQuery = true)
  Page<AccountEntity> findLastAccount(Pageable pageable);
}
